# -*- coding:utf-8 -*-
from conf.setting import CASE_DATA_PATH
from conf.setting import BODY_PATH

import os

from tools.operate_config import get_yaml,OperateConfig
from tools.operate_json import OperationJson


class GetHeaderjson:

    def __init__(self,env=None):
        if env is not None:
            self.env = env
        else:
            self.env = OperateConfig().get_node_value('ENV', 'env')   #获取的是172.16.1.20

            self.headers_json = os.path.join(BODY_PATH, "headers.json")  # 请求头json 文件 ；os.path.jion用于拼接多个路径字符串


            #self.headers_json = os.path.join(CASE_DATA_PATH, "body.json")   #请求体json文件
    #获取请求头
    #获取headers.json里名为"s_login_headers”的json串
    def get_s_login_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env,"s_login_headers")  #读json文件，例如：请求体-body

    #获取headers.json里名为"s_headers”的json串
    def get_s_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env,"s_headers")

    #用于登录成功将获取到的token值set进去：set_s_headers，往json文件里set字段值
    def set_s_headers(self,s_token):
        return OperationJson(self.headers_json).write_datas(s_token,self.env, "s_headers", "sToken")

    def get_login(self):
        return OperationJson(self.headers_json)


    def get_c_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env,"c_headers")
    def set_c_headers(self,s_token):
        OperationJson(self.headers_json).write_datas(s_token,self.env, "c_headers", "sToken")

    def get_w_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env, "w_headers")
    def set_w_headers(self,s_token):
        OperationJson(self.headers_json).write_datas(s_token,self.env, "w_headers", "sToken")
    def set_w_headers_companyId(self,companyId):
        OperationJson(self.headers_json).write_datas(companyId,self.env, "w_headers", "T-Id")



#读取请求体body.json文件
class GetcJson:
    def __init__(self,env=None):
        if env is not None:
            self.env = env
        else:

            self.env = OperateConfig().get_node_value('ENV', 'env')
            self.body_json = os.path.join(CASE_DATA_PATH, "body.json")  # 按配置文件设置的环境读取，比如这里读取的文件就是qa1_c.json

    def get_media_list_info(self):
        return OperationJson(self.body_json).key_get_data("queryMediaList")


    def get_tts(self):
        return OperationJson(self.body_json).key_get_data("speechSynthesisPlay")

    def set_timeType(self,s_timeType):
        return OperationJson(self.body_json).write_datas(s_timeType,"speechSynthesisPlay", "requestData","timeType")

    def set_playDuration(self, s_playDuration):
        return OperationJson(self.body_json).write_datas(s_playDuration, "speechSynthesisPlay", "requestData","playDuration")

    def get_login(self):
        return OperationJson(self.body_json).key_get_data("Login")













